package com.lx.thread.MyThread.lx;

import java.util.*;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.locks.ReentrantLock;

public class MyThread {
    public volatile static List<Integer>list= Collections.synchronizedList( new ArrayList<>());

    public static ReentrantLock reentrantLock=new ReentrantLock();

    public static Object object =new Object();

    public static Integer count=0;


    public  void insert(){
//        try {
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

    }


    public static void main(String[] args) throws InterruptedException {
        CyclicBarrier cyclicBarrier = new CyclicBarrier(10,()->{
            System.out.println("insert");
            System.out.println("insert method Thread name ="+Thread.currentThread().getName());
            System.out.println("insert method listSize="+list.size());


        });


        for (int i = 0; i < 20; i++) {
            new Thread(()-> {
                Random random = new Random(100);
                list.add(random.nextInt());
                System.out.println("list.size="+list.size());
                System.out.println("thread name is "+Thread.currentThread().getName());
                try {
                    cyclicBarrier.await();
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            }).start();
        }

    }
    public synchronized static void reloadCountDownLatch(){
        list.clear();

    }


    /**
     * <p>
     *
     * </p>
     * @param  list
     * @return void
     * @Author zlx
     * @date 2021/4/18
     */
    public  static void outSize(List list){
        System.out.println("list size print " +list.size());
    }




}